package com.wang.tool.lock;

import com.wang.tool.lock.aop.EnableLock;
import com.wang.tool.lock.core.DynamicLockConfigCenter;
import com.wang.tool.lock.core.LockConfig;
import com.wang.tool.util.CommonUtil;

public class LockConfigCenter {

    public static final LockConfig DEF_OPEN = new LockConfig();

    static {
        DEF_OPEN.setOpen(true);
    }


    /**
     * @see EnableLock#defLockWaitTime()
     */
    private static int defLockWaitTime;

    /**
     * @see EnableLock#defLockSecond()
     */
    private static int defLockSecond;


    /**
     * @see EnableLock#dynamicConfigCenter()
     */
    private static DynamicLockConfigCenter dynamicConfigCenter;


    public static LockConfig getLockConfig(String namespace){
        if (CommonUtil.isBlank(namespace)) {
            throw new IllegalArgumentException("namespace can not be null");
        }
        LockConfig lockConfig = dynamicConfigCenter.getLockConfig(namespace);
        return lockConfig == null ? DEF_OPEN : lockConfig;
    }



    public static int getDefLockWaitTime() {
        return defLockWaitTime;
    }

    public static void setDefLockWaitTime(int defLockWaitTime) {
        LockConfigCenter.defLockWaitTime = defLockWaitTime;
    }

    public static int getDefLockSecond() {
        return defLockSecond;
    }

    public static void setDefLockSecond(int defLockSecond) {
        LockConfigCenter.defLockSecond = defLockSecond;
    }

    public static DynamicLockConfigCenter getDynamicConfigCenter() {
        return dynamicConfigCenter;
    }

    public static void setDynamicConfigCenter(DynamicLockConfigCenter dynamicConfigCenter) {
        LockConfigCenter.dynamicConfigCenter = dynamicConfigCenter;
    }
}
